Director Article

3D User Interfaces and 3D App Building Using the Chrome Library Set of Behaviors

Karl Sigiscar

R3D

The Chrome Library set of 3D behaviors lets you quickly set up your scene with drag and drop behaviors to adjust rendering parameters. However, you can do much more. You can create a user interface on top of 3D sprites to control behaviors, or you can control a Macromedia Flash movie from the 3D scene. You can also create navigation interfaces using rollover models with associated links, or display a tooltip when rolling over a given model. To perform certain actions, UI behaviors allow you to call handlers on behaviors that are already assigned to the W3D sprite. Combining all of these, you can build more complex projects. The Chrome Library is free and available at the following address: www.chromelib.com

You will start where you left off in the first article dedicated to the Chrome Lib and add interactivity to the scene. You had a car displayed on a booth in the foreground with a screen in the background.

The mesh and textures of the car W3D files in this article were created by Stephen Magnardi. You can purchase the car W3D files used in this article from TurboSquid.com (search keyword: signum). However, you can use the Chrome Library behaviors on most any W3D file. Turbo Squid also has free W3D files that you can use to experiment with the Chrome Library behaviors. The W3D file of the car, wheels, and booth is made up of 21,603 polygons. Most textures are 256 x 256 pixels in size. Some textures are 512 x 512.

Requirements

To complete this tutorial you will need to install the following software and files:

Director MX 2004

Tutorials and sample files:

Purchase and download the W3D files from TurboSquid.com (search keyword: signum)

Setting Up the Texture Render Format

In the first article, you learned how to set up the texture render format to 32 bits so the alpha channel gradient of the headlights’ rays render properly. You also learned how to remove them from the scene. This time, you will leave the headlights visible.

The Texture Render Format behavior

Figure 1. The Texture Render Format behavior

Be sure the texture render format is set to 32 bit (RGBA8888) using the Texture Render Format behavior (see the first article). This will be important for providing a clean rendering on the overlay textures later on in the project.

The jaggy, non anti-aliased scene.

Figure 2. The jaggy, non–anti-aliased scene.

Setting Up Hardware Anti-Aliasing (FSAA)

If your 3D graphics card is Direct X compliant and is capable of hardware anti-aliasing (Full Screen Anti-Aliasing), you can activate it on your Shockwave 3D scene using the Chrome Lib. Even entry-level graphics cards such as the ATI Radeon 7000 are now endowed with FSAA under DirectX 7, so you can easily benefit from this feature. However, hardware anti-aliasing is only available with Director MX 2004 and version 10 of Macromedia Shockwave Player.

The Anti-Aliasing behavior

Figure 3. The Anti-Aliasing behavior

  1. Drag and drop the Anti-Aliasing behavior from the Chrome Lib onto the W3D sprite, either on the Stage or in the Score. The following dialog box appears:

  2. The Anti-Aliasing Parameters dialog box

    Figure 4. The Anti-Aliasing Parameters dialog box

  3. Check the Hardware Anti-Aliasing box. Click OK.
  4. Click the Play button in the Control panel or press Enter to start the movie. The scene is now anti-aliased and looks much better.

The smooth anti-aliased scene.

Figure 5. The smooth anti-aliased scene.

Not only does hardware anti-aliasing improve rendering quality—it doesn't slow rendering speed as is the case with software anti-aliasing. For hardware anti-aliasing, the graphics card GPU (Graphics Processing Unit) wires this function. For software anti-aliasing, it is the computer's CPU that does all the required computation, hence the slowdown.

Setting Up the Shader Blend Level for Reflection

The car body has been given an environment map by the graphic artist in 3DS Max. However, with the current parameters, the car body is way too shiny. You need to tweak the shader blend level to get the visual result you want. The blend level indicates how much the map is blended with the underlying diffuse color.

The Shader Blend behavior

Figure 6. The Shader Blend behavior

  1. Drag and drop the Shader Blend behavior from the Chrome Library onto the W3D sprite. You can do this either on the Stage or in the Score. The following dialog box appears:

    The Shader Blend dialog box

    Figure 7. The Shader Blend dialog box

  2. Select the Body Model and set the Shader Blend to 64%.
  3. Click OK.
  4. Click the Play button in the Control panel or press Enter to start the movie. The car body still reflects the reflection map, but it looks more realistic as it is less shiny.
The car with the correct shader blend level

Figure 8. The car with the correct shader blend level

Opening and Closing the Movable Parts of the Car

You want the user to be able to open and close the movable parts of the car, namely the hood, the trunk, the doors, and the seats. This is simple as you only have to care about the rotation on one axis. The pivot point of each separate model of the car has already been set in 3DS Max, so all movable parts rotate correctly about their axes.

Movable Parts of the Car
Hood Target Y axis rotation : 50.00
Trunk Target Y axis rotation : -65.00
Front seat left Target Y axis rotation : 20.00
Front seat right Target Y axis rotation : 20.00
Front door left Target Z axis rotation : -75.00
Front door right Target Z axis rotation : 75.00
Rear door left Target Z axis rotation : -75.00
Rear door right Target Z axis rotation : 75.00

  1. Drag and drop the Open/Close Model behavior from the Chrome Lib onto the W3D sprite, either on the Stage or in the Score.

    The Open/Close Model behavior

    Figure 9. The Open/Close Model behavior

    The following dialog box appears:

    The Open/Close Model parameters dialog box

    Figure 10. The Open/Close Model parameters dialog box

  2. Select the model you want to manipulate.
  3. Make sure the Copy Position parameter is checked and enter the correct rotation on the relevant axis, for example, 20 degrees on the Y axis for the Front Seat Right model.

    If the sliders are too touchy for you, enter precise values in the behavior tab of the Property inspector:

The Property inspector showing the Open/Close model behavior

Figure 11. The Property inspector showing the Open/Close model behavior

You must create an instance of the behavior for each model you want to open/close. In this case, you would have to drag and drop the same behavior eight times, each time with a different set of parameters (that is, a different model, axis, and rotation value).

Click the Play button in the Control panel or press Enter to start the movie. Click the hood, the trunk, the doors, or the seats, and they open in a smooth, progressive way. Click them again, and they will close in the same way. You can interrupt the opening or closing of a movable part while it rotates by clicking it, and it will immediately start rotating in the opposite direction. The rotation boundaries on the axis are defined by the original rotation and by the set target rotation behavior.

The car with the open hood and open driver door

Figure 12. The car with the hood and the driver door open

Creating a UI on Top of the 3D Scene

You will use the booth screen to display photographs of Paris and London to create ambiance for the booth. If you have ever been to a motor show, you know car makers always try to create ambiance for their booths. You want the user to be able to switch between photographs by clicking overlay buttons.

Import the nine bitmap cast members for full-size pictures and nine smaller ones for thumbnails. These should be imported into the internal cast and are included in the sample files download linked at the beginning of this article.

The 3D graphic artist created a shader called Booth Screen in the scene so you can display pictures onto the screen. It has an emissive color already set to white (RGB 255, 255, 255) in 3DS Max, so it looks realistic when you display pictures or videos on it.

For each photo button, you will apply two behaviors, the Environmental Mapping and Overlay Button UI behaviors, as shown below.

The Environment Mapping behavior

Figure 13a. The Environment Mapping behavior

The Overlay Button UI behavior

Figure 13b. The Overlay Button UI behavior

  1. Drag and drop the Environment Mapping behavior from the Chrome Library onto the W3D sprite, either on the Stage or in the Score. The following dialog box appears:

    The Environment Mapping Parameters dialog box

    Figure 14. The Environment Mapping Parameters dialog box

  2. Select Booth Screen as the shader to affect
  3. .
  4. Uncheck Affect all shaders.
  5. Select the Booth Screen model.
  6. Select the full-size picture you want to display on the booth screen for the bitmap parameter.
  7. Select texture as Mapping type.
  8. Click OK.
  9. Drag and drop the Overlay Button UI behavior from the Chrome Lib onto the W3D sprite, either on the Stage or in the Score. The following dialog box appears:

    The Overlay Button UI parameters dialog box

    Figure 15. The Overlay Button UI parameters dialog box

  10. Enter the relevant X and Y coordinates in pixels for the button position on top of the 3D scene. For instance, you want to have the buttons displayed at the bottom left corner of the scene.
  11. As you do not have several different bitmaps for the normal, pressed, rollover, and selected states, select the same thumbnail bitmap for all four states. This is mandatory. The thumbnail bitmap must match the full-sized image you selected in the first behavior.
  12. Uncheck Button Group as you do not want a radio button behavior and you are not creating a navigation interface, only click buttons.
  13. Select the W3D Sprite number (that is, the number of the sprite channel displaying the W3D cast member).
  14. Enter the Behavior number of the previously created behavior (the Environment Mapping behavior). You need this to tell Director what behavior this button will control. You can find a behavior number by looking at the behavior list in the Behavior tab of the Property inspector.
  15. Enter beginSprite() as the Handler call.
  16. Click OK.

Repeat these two steps for the nine photos.

Here is the behavior list of the W3D sprite in the Behavior inspector. As you can see, there are now quite a few behaviors assigned to the W3D sprite:

The Behavior inspector

Figure 16. The Behavior inspector

Click the Play button in the Control panel or press Enter to start the movie. The nine buttons appear at the bottom left corner on top of the 3D scene. By default, the first photo displayed on the screen is the one pointed to by the last assigned Environment Mapping behavior. Click any button, and the corresponding picture will display on the booth screen in the background.

The car with the 9 overlay buttons displayed

Figure 17. The car with the nine overlay buttons displayed

If you would like to have no picture displayed when the movie starts, use a blank bitmap as the thumbnail and a full-size image for the last button. This way, the first picture displayed on the booth screen will be blank (that is, white, beige, gray, or black). Also, when the user wants to disable picture viewing, he/she will be able to click the last button to reset the display. The nobackground.gif image is included in the sample files in the bitmaps/pictures folder (together with the nine photos) so you can experiment with this idea.

Changing the Camera

The graphic artist created and positioned a number of cameras in 3DS Max. You want the user to be able to switch from one view to the previous or next one with a camera travelling. For this purpose, you will use the Change Camera behavior in order to switch views, and you will use the Overlay Button UI to create the two necessary buttons to trigger the travelling.

The Change Camera behavior

Figure 18. The Change Camera behavior

The Overlay Button UI behavior

Figure 19. The Overlay Button UI behavior

  1. In the internal cast, import two 32-bit bitmap cast members with alpha channel depicting arrows, one pointing left, the other pointing right: btn_previous_camera and btn_next_camera. They are transparent so you can see the shape of them and see through. Both of these files are included in the sample files linked from the beginning of this article.
  2. Drag and drop the Change Camera behavior from the Chrome Library onto the W3D sprite, either on the Stage or in the Score. The following dialog box appears:
  3. The Change Camera parameters dialog box

    Figure 20. The Change Camera parameters dialog box

  4. Make sure the Cut parameter is unchecked and press OK.
  5. Drag and drop the Overlay Button UI behavior from the Chrome Library onto the W3D sprite, either on the Stage or in the Score. The following dialog box appears:

    The Overlay Button parameters dialog box

    Figure 21. The Overlay Button parameters dialog box

  6. Enter the relevant X and Y coordinates in pixels for the button position on top of the 3D scene. You want to have the two buttons displayed at the bottom right corner of the scene.
  7. As you do not have several different bitmaps for the normal, pressed, rollover and selected states, select the same btn_previous_camera bitmap cast member for all four states. This is mandatory.
  8. Uncheck Button Group, as you do not want a radio button behavior and you are not creating a navigation interface, only click buttons.
  9. Select the W3D Sprite number (that is, the number of the sprite channel displaying the W3D cast member).
  10. Enter the Behavior number of the previously created behavior (such as the Change Camera behavior). You need this to tell Director what behavior this button will control. You can find a behavior number by looking at the behavior list in the Behavior tab of the Property inspector.
  11. Enter previousCamera() as the Handler call.
  12. Click OK.
  13. Drag and drop the Overlay Button UI behavior from the Chrome Lib onto the W3D sprite, either on the Stage or in the Score. The following dialog box appears:

    The Overlay Button parameters dialog box

    Figure 22. The Overlay Button parameters dialog box

  14. Enter the relevant X and Y coordinates in pixels for the button position on top of the 3D scene. You want to have the two buttons displayed at the bottom right corner of the scene.
  15. As you do not have several different bitmaps for the normal, pressed, rollover, and selected states, select the same btn_next_camera bitmap cast member for all four states. This is mandatory.
  16. Uncheck Button Group as you do not want a radio button behavior and you are not creating a navigation interface but just click buttons
  17. .
  18. Select the W3D Sprite number ( that is, the number of the sprite channel displaying the W3D cast member).
  19. Enter the Behavior number of the previously created behavior (such as the Change Camera behavior). You need this to tell Director what behavior this button will control. You can know a behavior number by looking at the behavior list in the behavior tab of the Property inspector.
  20. Enter nextCamera() as the Handler call.
  21. Press OK.

Click the Play button in the Control panel or press Enter to start the movie. The previous and next camera buttons appear at the bottom right corner on top of the 3D scene. Click the next camera button (the right arrow). The camera travels smoothly to the next view (camera) present in the scene. Click the previous button (the left arrow). The camera travels smoothly to the previous view (camera) present in the scene. You can interrupt a travelling at anytime by clicking any of the two buttons to start travelling to another camera.

The camera travelling to another view

Figure 23. The camera travelling to another view

Here is the internal cast upon completion of the project:

The internal cast

Figure 24. The internal cast

(+) View larger

Creating a 3D Navigation System for a Website

In this next section, you will use the W3D file of a town that is included in the sample files linked from the beginning of this article. You want the user to be able to click a building to display a corresponding web page in a frame located in the lower part of the page.

  1. Create a new movie in Macromedia Director.
  2. Edit the Movie Properties in the Property inspector (Movie tab) and give the stage a size of 760 pixels in width and 300 in height.
  3. Drag and drop the town W3D cast member directly onto the Stage or onto the Score to have it centered automatically.
  4. Resize the W3D sprite directly on the Stage or in the Property inspector (Sprite tab) so it fits the Stage size (760 x 300).

    The town scene stage

    Figure 25. The town scene stage

  5. In Macromedia Dreamweaver or in a text editor, create an HTML document with the following HTML code:

    <FRAMESET ROWS="300, *"  border=0 scroll=no>
    <FRAME NAME="nav" SRC="sw3d_nav.htm"  scrolling=no>
    <FRAME NAME="display" SRC="default.htm">
    </FRAMESET>
    
    

    The first frame, nav, will display the navigation interface created with Shockwave 3D and will include the <OBJECT> and <EMBED> tag output by Director when publishing the movie. The second frame, whose name is display, will be the target frame in which the pages will be displayed.

  6. Save the frameset HTML document as index.html.
  7. Create a new page and name it default.htm. It will be the first page shown in the display frame.
  8. Create yet another page and enter some text. Save it as small_pyramid.html.
  9. In Macromedia Director, drag and drop the Go to URL with Rollover behavior onto the W3D sprite.

    The Go to URL with Rollover behavior

    Figure 26. The Go to URL with Rollover behavior

    The following dialog box appears:

    The Go to URL with Rollover parameters dialog box

    Figure 27. The Go to URL with Rollover parameters dialog box

  10. Select the small pyramid model and enter the URL to the corresponding page: small_pyramid.html.
  11. Select _targetname as Target and enter display as the target name (the name of the frame where you want to display pages).
  12. Create several instances of the Go to URL with Rollover behavior. Drag and drop it several times onto the W3D sprite, each time selecting a different model and entering a URL to another HTML document. But always specify display as the target frame.
  13. Edit the Publish Settings in the File menu of the movie. The following dialog box appears:

    The formats tab of the Publish Settings dialog box

    Figure 28. The formats tab of the Publish Settings dialog box

  14. Enter the name sw3d_nav.htm for the HTML file. This is important as the frameset document is already pointing to this file.
  15. In Windows Explorer or the Macintosh Finder, double-click the index.html file to launch the browser as shown in figure 29 below.
The project seen in Internet Explorer.

Figure 29. The project as viewed in Internet Explorer

When you roll the mouse over the small pyramid, it highlights in yellow, and the mouse cursor changes to a hand. Click the small pyramid, and the link is displayed in the display frame in the lower part the page as shown in figure 30 below.

The small_pyramid.htm file shown in the "display" frame.

Figure 30. The small pyramid.htm file shown in the display frame.

Controlling Macromedia Flash from Shockwave 3D

Now you will do almost the same thing, but in a different way. Instead of displaying an HTML document when a user clicks a model, you will have the playhead jump to a frame in an embedded Macromedia Flash movie. The FLA and SWF files of this tutorial are available in the sample files linked from the beginning of this article.

Note: You need Macromedia Flash MX 2004 to complete this section of the article. Download the trial, or purchase the full version.

  1. Start with the existing movie and select Save As to create a new one. Give it a file name of your choosing.
  2. Edit the Movie properties in the Property inspector (Movie tab). Give the Stage a size of 760 pixels in width and 600 pixels in height.

Next, you will create several different labelled keyframes. The Macromedia Flash playhead will jump to a keyframe when the mouse rolls over a given model. Another way would be to create different scenes with each a different name.

  1. In Macromedia Flash, create a new Flash movie.
  2. In the Property inspector, enter the label default for the current frame.
  3. Position the playhead on frame 20 and press F6 to create an empty keyframe.
  4. In the Property tab, enter the label small pyramid.

    The Flash Properties panel.

    Figure 31. The Flash Property inspector

    The Flash timeline with the "small pyramid" frame label.

    Figure 32. The Flash Timeline with the small pyramid frame label.

  5. Enter some relevant text on the Stage, such as small pyramid building. You could also import a picture and improve the layout or add a display effect. But keep it simple for now.
  6. Export the SWF file.
  7. In Macromedia Director, import the SWF file you just created.

    The Import files dialog box

    Figure 33. The Import files dialog box

  8. Drag and drop the SWF file from the internal cast onto the Stage, next to the W3D scene. You can tweak its position in the Tweak window or in the Sprite tab of the Property inspector.

    If you chose to link to the SWF file on importing (Media > Link to External File), you can access Macromedia Flash from within Director by clicking Launch External Editor in the contextual menu of the Flash cast member in the internal cast. This lets you modify it.

    The Launch External Editor menu option

    Figure 34. The Launch External Editor menu option

  9. Press Done in Macromedia Flash when you have finished altering the SWF file.

    Click done to return to Director

    Figure 35. Click Done to return to Director

    Using these steps, you can move back and forth between Macromedia Flash and Director until you are satisfied with the result.

    The Flash Control from Model behavior

    Figure 36. The Flash Control from Model behavior

  10. In Macromedia Director, drag and drop the Flash Control from Model behavior from the Chrome Library onto the W3D sprite, either on the Stage or in the Score. The following dialog box appears:

    The Flash Control from Model Parameters dialog box

    Figure 37. The Flash Control from Model Parameters dialog box

  11. Select Small Pyramid for the Model parameter.
  12. Select the relevant Flash Sprite number.
  13. Enter the frame label the playhead will jump to: small pyramid.
  14. By default, the 3D model rollover color is yellow. Click OK.
  15. Click the Play button in the Control panel or press Enter to start the movie.

When you roll the mouse over the small pyramid, it highlights in yellow and the mouse cursor changes to a hand. Click the small pyramid and the playhead of the Flash sprite jumps to the small pyramid label, displaying the contextual information about this building.

The completed project

Figure 38. The completed project

Here is the internal cast upon completion of the project:

The internal cast upon completion of the project

Figure 39. The internal cast upon completion of the project

Afterword

As it is, the town 3D navigation system is not much better than a page made with a simple HTML table containing clickable rollover images. However, imagine you combine the 3D navigation system with the camera travelling interface you created on top of the car scene in the first part of the article (with the previous and next camera arrow buttons). Users would then be able to travel the city from one district to another. Each district would have a number of active buildings, and users would be able to roll the mouse over and click buildings while travelling. You could then turn this into a powerful navigation system.

This is definitely something you could not do with a simple HTML page. The freely downloadable town W3D has a number of preset cameras, so you can experiment with this idea. The btn_previous_camera.png and btn_next_camera.png bitmaps are available in the sample files in the bitmaps/buttons folder.

Conclusion

The Chrome Library provides you with all the necessary building blocks to create a 3D User Interface on top of the scene, a truly interactive 3D application, or a 3D navigation system for a website. By creating several instances of the same behavior (such as the Overlay Button UI) and combining the different behaviors, you can create powerful rich media projects in no time.


About the author

Karl Sigiscar has been a multimedia and web developer since 1997, using Flash, Director and Java. He developed edutainment CD-Roms with Director as well as dynamic websites. In late 2000, Karl joined the Director 8.5 beta program. Since then, he has delved deeper into the many possibilities of Shockwave 3D (bipeds, particles, LOD). In 2002, Karl developed the Shockwave 3D architecture of the game Mogi Mogi for NewtGames as well as new ideas with a focus on 3D interactive model visualization, which are highly interactive (and responsive) product presentations, such as the Audi A8 in 3D with Gedas France. He designed the Chrome Lib set of 3D behaviors first to help graphic artists test their scenes by themselves in Director, then as a personal project with a focus on tweening FX. Karl thinks he has tweened everything possible: the color, the transparency, the fog color, the fog distance, the field of view and so on… He is now an ActionScript/Java developer for R3D in Paris, France.